package com.learn.spring.controller;

import com.learn.spring.entity.FluxUser;
import com.learn.spring.service.FluxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
public class FluxController {

    @Autowired
    public FluxService fluxService;

    @RequestMapping("findUser")
    public Mono<FluxUser> findUser(int id) {
        return fluxService.getUserById(id);
    }

    @GetMapping("user")
    public Flux<FluxUser> getAllUser() {
        return fluxService.getAllUser();
    }

    @PostMapping("saveUser")
    public Mono<Void> saveUser(FluxUser user) {
        return fluxService.addUser(Mono.just(user));
    }

}
